#include "test.h"
#ifdef TEST_ZLIB

#include <stdio.h>
#include <string.h>
#include "test.h"
#include "../zlib/zlib.h"


void test_zlib_main() {
	char buf[1024];
    char destbuf[1024];
    char buf2[1024];

    unsigned long lDestLen = 1024;

    memset(buf, 0, sizeof(buf));
    memset(destbuf, 0, sizeof(destbuf));
    memset(buf2, 0, sizeof(buf2));

    unsigned long srcLen = 64;
    for(int i=0; i<srcLen; ++i)
    {
        buf[i] = i;
    }
    buf [32] = 0;

    int iRet = ::compress((Bytef *)destbuf, &lDestLen, (Bytef *)buf, srcLen);
    if (Z_OK == iRet)
    {
        printf("compress ok dest len %d\n", lDestLen);

        unsigned long lBuf2Len = 1024;
        iRet = ::uncompress((Bytef *)buf2, &lBuf2Len, (Bytef *)destbuf, lDestLen);
        if (Z_OK == iRet)
        {
            printf("uncompress ok dest len %d\n", lBuf2Len);
            if (lBuf2Len != srcLen)
            {
                printf("uncompress len Different\n");
            }
            else if (memcmp(buf, buf2, lBuf2Len) != 0)
            {
                printf("uncompress data Different\n");
            }
            else
            {
                printf("uncompress data same\n");
            }
        }
        else
        {
            printf("uncompress error: %d\n", iRet);
        }
    }
    else
    {
        printf("compress error: %d\n", iRet);
    }

}

#endif